package jnpf.database.datatype.limit;

import jnpf.database.datatype.limit.base.DtLimitBase;
import jnpf.database.datatype.limit.base.DtLimitModel;
import jnpf.database.datatype.limit.util.DtLimitUtil;
import jnpf.database.datatype.model.DataTypeModel;
import jnpf.database.datatype.model.ViewDtModel;

/**
 * 类功能
 *
 * @author JNPF开发平台组 YanYu
 * @version V3.3
 * @copyright 引迈信息技术有限公司
 * @date 2022-06-06
 */
public class StringLimit extends DtLimitBase {

    public final static String CATEGORY = "type-String";
    public final static String JAVA_TYPE = "String";

    public StringLimit(Long fixedCharLength){
        instanceCommon(false, fixedCharLength, null, null);
    }

    public StringLimit(){
        instanceCommon(false, null, null, null);
    }

    public StringLimit(Boolean modifyFlag, Long defaultCharLength, Long maxCharLength){
        instanceCommon(modifyFlag, null, defaultCharLength, maxCharLength);
    }

    public void instanceCommon(Boolean isModifyFlag, Long fixedCharLength, Long defaultCharLength, Long maxCharLength){
        this.dtCategory = CATEGORY;
        this.isModifyFlag = isModifyFlag;
        // 字符长度
        DtLimitModel charLengthModel = new DtLimitModel();
        charLengthModel.setFixed(fixedCharLength);
        charLengthModel.setDefaults(defaultCharLength);
        charLengthModel.setMax(maxCharLength);
        this.charLengthLm = charLengthModel;
    }

    @Override
    public DataTypeModel convert(ViewDtModel viewDtModel){
        DataTypeModel dataTypeModel = DtLimitUtil.convertCharacter(viewDtModel);
        if(this.isModifyFlag){
            DtLimitUtil.getCharLength(dataTypeModel);
        }
        dataTypeModel.setJavaType(JAVA_TYPE);
        return dataTypeModel;
    }


}
